package com.dyw.ssmp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dyw.ssmp.entity.Book;
import com.dyw.ssmp.mapper.BookMapper;
import com.dyw.ssmp.service.BookService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Devil
 * @create 2022-01-23-21:54
 */
@Service
@SuppressWarnings("all")
public class BookServiceImpl extends ServiceImpl<BookMapper,Book> implements BookService{
    @Autowired
    private BookMapper mapper;


    @Override
    public List<Book> getAll() {
        return mapper.selectList(null);
    }

    @Override
    public IPage<Book> getPage(int currentPage, int pageSize, Book book) {
        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<>();

        lqw.like(Strings.isNotEmpty(book.getType()),Book::getType,book.getType()).
        like(Strings.isNotEmpty(book.getName()),Book::getName,book.getName())
        .like(Strings.isNotEmpty(book.getDescription()),Book::getDescription,book.getDescription());

        IPage<Book> page = new Page<>(currentPage,pageSize);
        mapper.selectPage(page,lqw);
        return page;
    }
}
